% read synapses from a file and store into sparse array variable syn
% syn(pre,post)=w from pre to post.
% The file *.syn has the first column the post and the second column the
% pre.
read_groups
if ~exist('NP')
    disp('NP, the number of processors must be set first.');
end
NP
proc = 0;
synfile = [ num2str(proc) '-' num2str(neuron_id(end,end)+1) '.syn'];
X=load(synfile);
syn=sparse(X(:,2)+1,X(:,1)+1,X(:,3),max(neuron_id(:,1)),max(neuron_id(:,1)));


synfile = [ num2str(proc) '-' num2str(neuron_id(end,end)+1) 'final.syn'];
X=load(synfile);
syn_final=sparse(X(:,2)+1,X(:,1)+1,X(:,3),max(neuron_id(:,1)),max(neuron_id(:,1)));

for proc = 1:NP-1
synfile = [ num2str(proc) '-' num2str(neuron_id(end,end)+1) '.syn'];
X=load(synfile);
syn=syn+sparse(X(:,2)+1,X(:,1)+1,X(:,3),max(neuron_id(:,1)),max(neuron_id(:,1)));


synfile = [ num2str(proc) '-' num2str(neuron_id(end,end)+1) 'final.syn'];
X=load(synfile);
syn_final=syn_final+sparse(X(:,2)+1,X(:,1)+1,X(:,3),max(neuron_id(:,1)),max(neuron_id(:,1)));

end